package linter.linterjava.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageInfo;
import linter.linterjava.POJO.DO.CurriculumNote;
import linter.linterjava.POJO.DTO.CurriculumNoteDTO;
import linter.linterjava.POJO.UtilDTO.PageInfoDTO;
import linter.linterjava.mapper.CurriculumMapper;
import linter.linterjava.service.CurriculumNoteService;
import linter.linterjava.mapper.CurriculumNoteMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

import static linter.linterjava.custom.ConstantPublicWay.getList;
import static linter.linterjava.custom.ConstantPublicWay.getPageInfo;
import static linter.linterjava.custom.CustomResultType.CREATION_ERROR;
import static linter.linterjava.custom.CustomResultType.CREATION_SUCCESS;

/**
* @author 北煜
* @description 针对表【curriculum_note(课程笔记表)】的数据库操作Service实现
* @createDate 2024-07-13 19:25:58
*/
@Service
public class CurriculumNoteServiceImpl extends ServiceImpl<CurriculumNoteMapper, CurriculumNote>
    implements CurriculumNoteService{

    @Resource
    CurriculumMapper curriculumMapper;
    @Resource
    CurriculumNoteMapper curriculumNoteMapper;

    @Override
    public String createCurriculumNote(CurriculumNoteDTO curriculumNoteDTO, Long uuid) {
        // 先使用课程id得到课程名字作为笔记名称，
        Date date = new Date();
        String name = curriculumMapper.getCurriculumName(curriculumNoteDTO.getCurriculumId());
        CurriculumNote curriculumNote = new CurriculumNote();
        curriculumNote.setCurriculumId(curriculumNoteDTO.getCurriculumId());
        curriculumNote.setCurriculumNoteTitle(name);
        curriculumNote.setCurriculumType(curriculumNoteDTO.getCurriculumType());
        curriculumNote.setContent(curriculumNoteDTO.getContent());
        curriculumNote.setUserId(uuid);
        curriculumNote.setCreatTime(date);
        curriculumNote.setUpdataTime(date);
        int flag = curriculumNoteMapper.insert(curriculumNote);
        return flag > 0 ? CREATION_SUCCESS : CREATION_ERROR;
    }

    // TODO：或许存在隐患
    @Override
    public CurriculumNote getCurriculumNoteById(CurriculumNoteDTO curriculumNoteDTO, Long uuid) {
        return curriculumNoteMapper.selectById(curriculumNoteDTO.getId());
    }

    @Override
    public List<CurriculumNote> getCurriculumNoteList(Long uuid) {
        return getList(new QueryWrapper<CurriculumNote>()
                .eq("user_id", uuid).eq("is_delete",0),
                curriculumNoteMapper);
    }

    @Override
    public List<CurriculumNote> queryCurriculumNote(CurriculumNoteDTO curriculumNoteDTO, Long uuid) {
        return getList(new QueryWrapper<CurriculumNote>()
                .like("curriculum_note_title","%"+curriculumNoteDTO.getCurriculumNoteTitle()+"%").or()
                .like("content","%"+curriculumNoteDTO.getContent()+"%").or()
                .like("curriculum_type","%"+curriculumNoteDTO.getCurriculumType()+"%")
                .eq("user_id",uuid).eq("is_delete",0),
                curriculumNoteMapper);

    }
}




